package com.atguigu.springboot.controller;

import com.atguigu.springboot.entity.User;
import com.atguigu.springboot.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserRepository userRepository ;

    @RequestMapping("/user/{id}")
    public User getUser(@PathVariable("id") Integer id) {
        return userRepository.findOne(id) ;
    }
    @RequestMapping("/user")
    public User insertUser(User user) {
        return userRepository.save(user) ;
    }
}
